﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Pop
{
    class Pallet:Object
    {

        //public int debugAreadeImpacto;


        public Pallet(Texture2D texture, Vector2 position):base(texture,position)//<CONSTRUTOR!!!
        {
            //this.texture = texture;
            this.position = position;
            this.velocity = new Vector2(10, 0);
            this.size = texture.Bounds;
            this.size.X = (int)position.X;
            this.size.Y = (int)position.Y;
        }



        public void Update(GameWindow janela, List<Keys> teclas)//AQUI!!!
        {

            ManternaJanela(janela);

                foreach (Keys tecla in teclas)
                {
                    if (Keyboard.GetState().IsKeyDown(tecla)
                        && tecla == Keys.Down)
                    {
                        position += velocity;//AQUI
                    }

                    if (Keyboard.GetState().IsKeyDown(tecla)
                        && tecla == Keys.Up)
                    {
                        position -= velocity;
                    }

                    if (Keyboard.GetState().IsKeyDown(tecla)
                        && tecla == Keys.Z)
                    {
                        position += velocity;
                    }

                    if (Keyboard.GetState().IsKeyDown(tecla)
                        && tecla == Keys.A)
                    {
                        position -= velocity;
                    }
                    if (Keyboard.GetState().IsKeyDown(tecla)
                        && tecla == Keys.Left)
                    {
                        position -= velocity;
                    }

                    if (Keyboard.GetState().IsKeyDown(tecla)
                        && tecla == Keys.Right)
                    {
                        position += velocity;
                    }
                }

                size.X = (int)position.X;
                size.Y = (int)position.Y;
        
        }

        public void UpdatePalhetaIA(Ball ball)
        {
            if (ball.Position.Y + ball.Size.Height / 2 > position.Y + size.Height / 2)
            {
                position.Y += velocity.Y;
            }
            else
            {
                position.Y -= velocity.Y;
            }
        }

        void ManternaJanela(GameWindow janela)
        {
            if (position.Y <= 0)
            {
                position.Y = 0;
            }

            if (position.Y >= janela.ClientBounds.Height - size.Height)
            {
                position.Y = janela.ClientBounds.Height - size.Height;
            }

            if (position.X <= 0)
            {
                position.X = 0;
            }

            if (position.X >= janela.ClientBounds.Width - size.Width)
            {
                position.X = janela.ClientBounds.Width - size.Width;
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, position, Color.White);
        }
    }
}
